package cn.it.dao;

import cn.it.pojo.Menu;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MenuDao {


   /* @Select("select * from t_menu where level=1")
    @Results({
            @Result(column = "id", property = "id", id = true),
            @Result(property = "children", column = "id", many = @Many(select = "cn.it.dao.MenuDao.findChildrenById"))
    })
    public List<Menu> findAll();*/


    @Select("select * from t_menu where parentMenuId=#{id}")
    public List<Menu> findChildrenById(Integer id);

    @Select("select * from t_menu where id in (select menu_id from t_role_menu where role_id = (select id from  t_user where username=#{username}))and level = '1'")
    @Results({
            @Result(column = "id", property = "id", id = true),
            @Result(property = "children", column = "id", many = @Many(select = "cn.it.dao.MenuDao.findChildrenById"))
    })
    List<Menu> findMenuAll(String username);


}
